<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜单授权</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css" media="all">
</head>
<body>
<div style="margin: 10px 10px 10px 10px;">
    <!--数据表格主体-->
    <table id="munu-parent-table" lay-filter="munu-parent-table"></table>
</div>
<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script>

    var insTb;

    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    };

    layui.extend({
        treeTable: '/static/js/lay-module/treetable-lay/treeTable' //table树形扩展
    }).use(['treeTable'], function () {
        var $ = layui.jquery;
        var treeTable = layui.treeTable;
        // 渲染树形表格
        insTb = treeTable.render({
            elem: '#munu-parent-table',
            url: '/sys/menu/list',        //获取所有的菜单权限列表
            tree: {
                iconIndex: 1,           // 折叠图标显示在第几列
                isPidData: true,        // 是否是id、pid形式数据
                idName: 'id',  // id字段名称
                pidName: 'parentId',     // pid字段名称
                getIcon: function (obj) {
                    return '';
                }
            },
            cols: [
                [
                    {type: 'checkbox'},
                    {field: 'title', width: '50%', title: '菜单名称'},
                    {field: 'description', width: '50%', title: '描述', align: 'center'}
                ]
            ],
            done:function(res){
                $.ajax({
                    type: "get",
                    url: "/sys/role/menu/list?id="+getQueryString('id'),     //获取用户拥有的权限
                    dataType: "json",
                    traditional: true,
                    success: function (data) {
                        insTb.setChecked(data.data);
                    },
                    error: function (data) {
                        layer.closeAll();
                        layer.msg(data);
                    }
                })
            },
            skin: 'line'
        });
    });
</script>

</body>
</html>